﻿using System;
using System.Text;

namespace Mido.Utils.Logging
{
    public class LogWindowViewModel
    {
        private readonly LogWindowModel _model;

        internal LogWindowViewModel(LogWindowModel model)
        {
            if (model == null) 
                throw new ArgumentNullException("model");
            
            _model = model;
        }

        public string Message
        {
            get { return _model.Exception.Message; }
        }

        public string StackTrace
        {
            get
            {
                StringBuilder builder = new StringBuilder();

                Exception temp = _model.Exception;
                while (temp != null)
                {
                    builder.AppendLine(temp.Message);
                    builder.AppendLine(temp.StackTrace);

                    temp = temp.InnerException;
                }

                return builder.ToString();
            }
        }

        public static LogWindowViewModel Designer
        {
            get
            {
                LogWindowModel model = new LogWindowModel(new Exception("Test exception", new Exception("Inner Exception")));
                return new LogWindowViewModel(model);
            }
        }
    }
}
